package com.itmiaojie.controller;

import com.itmiaojie.pojo.ResponseResult;
import com.itmiaojie.pojo.dto.ArticleDto;
import com.itmiaojie.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/content/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @PostMapping
    public ResponseResult insertArticle(@RequestBody ArticleDto articleDto){
        System.err.println(articleDto);
        return articleService.insertArticle(articleDto);
    }
    /**
     * http://localhost:81/dev-api/content/article/list?pageNum=1&pageSize=10&title=123&summary=123
     */
    @GetMapping("/list")
    public ResponseResult list(Integer pageNum,Integer pageSize,String title,String summary){
        return articleService.getPageCategoryList(pageNum,pageSize,title,summary);
    }
    @GetMapping("/{id}")
    public ResponseResult getArticle(@PathVariable Long id){
        return articleService.getArticleById(id);
    }

    @PutMapping
    public ResponseResult update(@RequestBody ArticleDto articleDto){
        return articleService.updateArticle(articleDto);
    }
    @DeleteMapping("/{id}")
    public ResponseResult delArticle(@PathVariable Long id){
        return articleService.deleteArticleById(id);
    }
}
